using System;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading;

namespace CStock
{
   

    public class DatafeedHandler: StockObjectBase
    {
        protected static bool webClientBusy;
        protected static System.Net.WebClient webclient;
        protected IDataItem dataItem;
        protected DateTime dateStart;
        protected string url;


        public DatafeedHandler()
        {
            webclient = new System.Net.WebClient();

        }
        protected static StringCollection ReadPage_ToStringCollection(string myURL)
        {

            webClientBusy = true;
            System.IO.Stream stream = null;
            try
            {
                stream = webclient.OpenRead(myURL);

            }
            catch
            {
            }
            if (stream == null)
            {
                Debug.WriteLine("Have to wait - web client busy");
                webClientBusy = false;
                System.Windows.Forms.MessageBox.Show("Error downloading stream for : " + myURL);
                return null;
                
            }

            StreamReader sr = new StreamReader(stream);
            System.Collections.Specialized.StringCollection strCollection = new System.Collections.Specialized.StringCollection();

            string line;
            // Read and display lines from the file until the end of 
            // the file is reached.
            while ((line = sr.ReadLine()) != null)
            {
                strCollection.Add(line);
            }

            webClientBusy = false;
            return strCollection;

        }

        protected bool CheckDataItem()
        {
            Debug.Assert(dataItem != null);
            if (dataItem == null)
                return false;
            //Debug.Assert(dataItem.Symbol != null || dataItem.Symbol != string.Empty);
            if (dataItem.Symbol == null || dataItem.Symbol == string.Empty)
            {
                System.Windows.Forms.MessageBox.Show("For getting data for equity: " + dataItem.ID + " - please set SYMBOL and retry");
                return false;
            }
            return true;
        }
    }
}